﻿Imports System.Data.SqlClient
Imports MySql.Data.MySqlClient

Public Class frmNAP_DAUKY_TonCongNoNVBH
    Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents btnNew As System.Windows.Forms.Button
    Friend WithEvents btnSave As System.Windows.Forms.Button
    Friend WithEvents btnDelete1 As System.Windows.Forms.Button
    Friend WithEvents txtTienCuoiKy As System.Windows.Forms.TextBox
    Friend WithEvents BtnClose As System.Windows.Forms.Button
    Friend WithEvents TxtKH As System.Windows.Forms.TextBox
    Friend WithEvents Label9 As System.Windows.Forms.Label
    Friend WithEvents DataGridView1 As System.Windows.Forms.DataGridView
    Friend WithEvents TentaikhoanDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents RecycleIDDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents MataikhoanDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents NodauvnDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents CodauvnDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents PsnovnDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents PscovnDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents LknovnDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents LkcovnDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents NocuoivnDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents CocuoivnDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents TbldottoncongnokhachhangBindingSource As System.Windows.Forms.BindingSource
    Friend WithEvents DataSetNAP_DAUKY As PHUQUI.DataSetNAP_DAUKY
    Friend WithEvents DataGridViewTextBoxColumn1 As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents MakhachhangDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents ThanhtiendaukyDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents PhatsinhnotrongkyDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents ThanhtoantrongkyDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents ThanhtiencuoikyDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents gridViewSearch1 As System.Windows.Forms.DataGridView
    Friend WithEvents TblsearchBindingSource As System.Windows.Forms.BindingSource
    Friend WithEvents DataSetSearch As PHUQUI.DataSetSearch
    Friend WithEvents ma As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents ten As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents CBoKH As MTGCComboBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmNAP_DAUKY_TonCongNoNVBH))
        Dim DataGridViewCellStyle1 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle
        Dim DataGridViewCellStyle2 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle
        Dim DataGridViewCellStyle3 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle
        Dim DataGridViewCellStyle4 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle
        Dim DataGridViewCellStyle5 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle
        Me.btnSave = New System.Windows.Forms.Button
        Me.txtTienCuoiKy = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.btnNew = New System.Windows.Forms.Button
        Me.btnDelete1 = New System.Windows.Forms.Button
        Me.BtnClose = New System.Windows.Forms.Button
        Me.TxtKH = New System.Windows.Forms.TextBox
        Me.Label9 = New System.Windows.Forms.Label
        Me.DataGridView1 = New System.Windows.Forms.DataGridView
        Me.DataGridViewTextBoxColumn1 = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.MakhachhangDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.ThanhtiendaukyDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.PhatsinhnotrongkyDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.ThanhtoantrongkyDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.ThanhtiencuoikyDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.TbldottoncongnokhachhangBindingSource = New System.Windows.Forms.BindingSource(Me.components)
        Me.DataSetNAP_DAUKY = New PHUQUI.DataSetNAP_DAUKY
        Me.CBoKH = New MTGCComboBox
        Me.gridViewSearch1 = New System.Windows.Forms.DataGridView
        Me.TblsearchBindingSource = New System.Windows.Forms.BindingSource(Me.components)
        Me.DataSetSearch = New PHUQUI.DataSetSearch
        Me.ma = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.ten = New System.Windows.Forms.DataGridViewTextBoxColumn
        CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.TbldottoncongnokhachhangBindingSource, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.DataSetNAP_DAUKY, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.gridViewSearch1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.TblsearchBindingSource, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.DataSetSearch, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'btnSave
        '
        Me.btnSave.BackColor = System.Drawing.Color.Transparent
        Me.btnSave.Image = CType(resources.GetObject("btnSave.Image"), System.Drawing.Image)
        Me.btnSave.Location = New System.Drawing.Point(274, 99)
        Me.btnSave.Name = "btnSave"
        Me.btnSave.Size = New System.Drawing.Size(96, 24)
        Me.btnSave.TabIndex = 3
        Me.btnSave.UseVisualStyleBackColor = False
        '
        'txtTienCuoiKy
        '
        Me.txtTienCuoiKy.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtTienCuoiKy.Location = New System.Drawing.Point(237, 68)
        Me.txtTienCuoiKy.MaxLength = 100
        Me.txtTienCuoiKy.Name = "txtTienCuoiKy"
        Me.txtTienCuoiKy.Size = New System.Drawing.Size(131, 22)
        Me.txtTienCuoiKy.TabIndex = 2
        Me.txtTienCuoiKy.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(150, 70)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(84, 19)
        Me.Label2.TabIndex = 12
        Me.Label2.Text = "Tiền nợ cuối kỳ"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.Color.Transparent
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(123, 5)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(561, 24)
        Me.Label1.TabIndex = 11
        Me.Label1.Text = "NẠP ĐẦU KỲ CÔNG NỢ NHÂN VIÊN BÁN HÀNG"
        '
        'btnNew
        '
        Me.btnNew.Image = CType(resources.GetObject("btnNew.Image"), System.Drawing.Image)
        Me.btnNew.Location = New System.Drawing.Point(154, 99)
        Me.btnNew.Name = "btnNew"
        Me.btnNew.Size = New System.Drawing.Size(96, 24)
        Me.btnNew.TabIndex = 4
        '
        'btnDelete1
        '
        Me.btnDelete1.Image = CType(resources.GetObject("btnDelete1.Image"), System.Drawing.Image)
        Me.btnDelete1.Location = New System.Drawing.Point(394, 99)
        Me.btnDelete1.Name = "btnDelete1"
        Me.btnDelete1.Size = New System.Drawing.Size(96, 24)
        Me.btnDelete1.TabIndex = 29
        '
        'BtnClose
        '
        Me.BtnClose.Image = CType(resources.GetObject("BtnClose.Image"), System.Drawing.Image)
        Me.BtnClose.Location = New System.Drawing.Point(510, 99)
        Me.BtnClose.Name = "BtnClose"
        Me.BtnClose.Size = New System.Drawing.Size(96, 24)
        Me.BtnClose.TabIndex = 30
        '
        'TxtKH
        '
        Me.TxtKH.BackColor = System.Drawing.SystemColors.Window
        Me.TxtKH.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TxtKH.Location = New System.Drawing.Point(369, 41)
        Me.TxtKH.MaxLength = 500
        Me.TxtKH.Name = "TxtKH"
        Me.TxtKH.Size = New System.Drawing.Size(245, 22)
        Me.TxtKH.TabIndex = 100
        '
        'Label9
        '
        Me.Label9.Location = New System.Drawing.Point(150, 43)
        Me.Label9.Name = "Label9"
        Me.Label9.Size = New System.Drawing.Size(84, 19)
        Me.Label9.TabIndex = 45
        Me.Label9.Text = "Mã NVBH"
        Me.Label9.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'DataGridView1
        '
        Me.DataGridView1.AllowUserToAddRows = False
        Me.DataGridView1.AllowUserToDeleteRows = False
        Me.DataGridView1.AllowUserToResizeColumns = False
        Me.DataGridView1.AutoGenerateColumns = False
        Me.DataGridView1.BackgroundColor = System.Drawing.Color.LightBlue
        DataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter
        DataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control
        DataGridViewCellStyle1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        DataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText
        DataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight
        DataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText
        DataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.[True]
        Me.DataGridView1.ColumnHeadersDefaultCellStyle = DataGridViewCellStyle1
        Me.DataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
        Me.DataGridView1.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Me.DataGridViewTextBoxColumn1, Me.MakhachhangDataGridViewTextBoxColumn, Me.ThanhtiendaukyDataGridViewTextBoxColumn, Me.PhatsinhnotrongkyDataGridViewTextBoxColumn, Me.ThanhtoantrongkyDataGridViewTextBoxColumn, Me.ThanhtiencuoikyDataGridViewTextBoxColumn})
        Me.DataGridView1.DataSource = Me.TbldottoncongnokhachhangBindingSource
        Me.DataGridView1.Location = New System.Drawing.Point(42, 134)
        Me.DataGridView1.Name = "DataGridView1"
        Me.DataGridView1.ReadOnly = True
        Me.DataGridView1.Size = New System.Drawing.Size(709, 427)
        Me.DataGridView1.TabIndex = 46
        '
        'DataGridViewTextBoxColumn1
        '
        Me.DataGridViewTextBoxColumn1.DataPropertyName = "recycleID"
        DataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter
        Me.DataGridViewTextBoxColumn1.DefaultCellStyle = DataGridViewCellStyle2
        Me.DataGridViewTextBoxColumn1.HeaderText = "Tháng "
        Me.DataGridViewTextBoxColumn1.Name = "DataGridViewTextBoxColumn1"
        Me.DataGridViewTextBoxColumn1.ReadOnly = True
        Me.DataGridViewTextBoxColumn1.Width = 120
        '
        'MakhachhangDataGridViewTextBoxColumn
        '
        Me.MakhachhangDataGridViewTextBoxColumn.DataPropertyName = "ma_khachhang"
        DataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter
        Me.MakhachhangDataGridViewTextBoxColumn.DefaultCellStyle = DataGridViewCellStyle3
        Me.MakhachhangDataGridViewTextBoxColumn.HeaderText = "Mã Khách hàng"
        Me.MakhachhangDataGridViewTextBoxColumn.Name = "MakhachhangDataGridViewTextBoxColumn"
        Me.MakhachhangDataGridViewTextBoxColumn.ReadOnly = True
        Me.MakhachhangDataGridViewTextBoxColumn.Width = 120
        '
        'ThanhtiendaukyDataGridViewTextBoxColumn
        '
        Me.ThanhtiendaukyDataGridViewTextBoxColumn.DataPropertyName = "thanhtien_dauky"
        Me.ThanhtiendaukyDataGridViewTextBoxColumn.HeaderText = "thanhtien_dauky"
        Me.ThanhtiendaukyDataGridViewTextBoxColumn.Name = "ThanhtiendaukyDataGridViewTextBoxColumn"
        Me.ThanhtiendaukyDataGridViewTextBoxColumn.ReadOnly = True
        Me.ThanhtiendaukyDataGridViewTextBoxColumn.Visible = False
        '
        'PhatsinhnotrongkyDataGridViewTextBoxColumn
        '
        Me.PhatsinhnotrongkyDataGridViewTextBoxColumn.DataPropertyName = "phatsinhno_trongky"
        Me.PhatsinhnotrongkyDataGridViewTextBoxColumn.HeaderText = "phatsinhno_trongky"
        Me.PhatsinhnotrongkyDataGridViewTextBoxColumn.Name = "PhatsinhnotrongkyDataGridViewTextBoxColumn"
        Me.PhatsinhnotrongkyDataGridViewTextBoxColumn.ReadOnly = True
        Me.PhatsinhnotrongkyDataGridViewTextBoxColumn.Visible = False
        '
        'ThanhtoantrongkyDataGridViewTextBoxColumn
        '
        Me.ThanhtoantrongkyDataGridViewTextBoxColumn.DataPropertyName = "thanhtoan_trongky"
        Me.ThanhtoantrongkyDataGridViewTextBoxColumn.HeaderText = "thanhtoan_trongky"
        Me.ThanhtoantrongkyDataGridViewTextBoxColumn.Name = "ThanhtoantrongkyDataGridViewTextBoxColumn"
        Me.ThanhtoantrongkyDataGridViewTextBoxColumn.ReadOnly = True
        Me.ThanhtoantrongkyDataGridViewTextBoxColumn.Visible = False
        '
        'ThanhtiencuoikyDataGridViewTextBoxColumn
        '
        Me.ThanhtiencuoikyDataGridViewTextBoxColumn.DataPropertyName = "thanhtien_cuoiky"
        DataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight
        DataGridViewCellStyle4.Format = "N0"
        Me.ThanhtiencuoikyDataGridViewTextBoxColumn.DefaultCellStyle = DataGridViewCellStyle4
        Me.ThanhtiencuoikyDataGridViewTextBoxColumn.HeaderText = "Tiền cuối kỳ"
        Me.ThanhtiencuoikyDataGridViewTextBoxColumn.Name = "ThanhtiencuoikyDataGridViewTextBoxColumn"
        Me.ThanhtiencuoikyDataGridViewTextBoxColumn.ReadOnly = True
        Me.ThanhtiencuoikyDataGridViewTextBoxColumn.Width = 180
        '
        'TbldottoncongnokhachhangBindingSource
        '
        Me.TbldottoncongnokhachhangBindingSource.DataMember = "tbl_dot_toncongno_khachhang"
        Me.TbldottoncongnokhachhangBindingSource.DataSource = Me.DataSetNAP_DAUKY
        '
        'DataSetNAP_DAUKY
        '
        Me.DataSetNAP_DAUKY.DataSetName = "DataSetNAP_DAUKY"
        Me.DataSetNAP_DAUKY.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema
        '
        'CBoKH
        '
        Me.CBoKH.ArrowBoxColor = System.Drawing.SystemColors.Control
        Me.CBoKH.ArrowColor = System.Drawing.Color.Black
        Me.CBoKH.BindedControl = Nothing
        Me.CBoKH.BorderStyle = MTGCComboBox.TipiBordi.Fixed3D
        Me.CBoKH.CharacterCasing = System.Windows.Forms.CharacterCasing.Normal
        Me.CBoKH.ColumnNum = 1
        Me.CBoKH.ColumnWidth = "121"
        Me.CBoKH.DisabledArrowBoxColor = System.Drawing.SystemColors.Control
        Me.CBoKH.DisabledArrowColor = System.Drawing.Color.LightGray
        Me.CBoKH.DisabledBackColor = System.Drawing.SystemColors.Control
        Me.CBoKH.DisabledBorderColor = System.Drawing.SystemColors.InactiveBorder
        Me.CBoKH.DisabledForeColor = System.Drawing.SystemColors.GrayText
        Me.CBoKH.DisplayMember = "Text"
        Me.CBoKH.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.CBoKH.DropDownBackColor = System.Drawing.Color.FromArgb(CType(CType(193, Byte), Integer), CType(CType(210, Byte), Integer), CType(CType(238, Byte), Integer))
        Me.CBoKH.DropDownForeColor = System.Drawing.Color.Black
        Me.CBoKH.DropDownStyle = MTGCComboBox.CustomDropDownStyle.DropDown
        Me.CBoKH.DropDownWidth = 141
        Me.CBoKH.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.CBoKH.GridLineColor = System.Drawing.Color.LightGray
        Me.CBoKH.GridLineHorizontal = False
        Me.CBoKH.GridLineVertical = False
        Me.CBoKH.LoadingType = MTGCComboBox.CaricamentoCombo.ComboBoxItem
        Me.CBoKH.Location = New System.Drawing.Point(237, 41)
        Me.CBoKH.ManagingFastMouseMoving = True
        Me.CBoKH.ManagingFastMouseMovingInterval = 30
        Me.CBoKH.Name = "CBoKH"
        Me.CBoKH.SelectedItem = Nothing
        Me.CBoKH.SelectedValue = Nothing
        Me.CBoKH.Size = New System.Drawing.Size(131, 23)
        Me.CBoKH.TabIndex = 1
        '
        'gridViewSearch1
        '
        Me.gridViewSearch1.AllowUserToAddRows = False
        Me.gridViewSearch1.AllowUserToDeleteRows = False
        Me.gridViewSearch1.AllowUserToResizeColumns = False
        Me.gridViewSearch1.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.gridViewSearch1.AutoGenerateColumns = False
        Me.gridViewSearch1.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells
        Me.gridViewSearch1.BackgroundColor = System.Drawing.Color.LightBlue
        DataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter
        DataGridViewCellStyle5.BackColor = System.Drawing.SystemColors.Control
        DataGridViewCellStyle5.Font = New System.Drawing.Font("Arial", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        DataGridViewCellStyle5.ForeColor = System.Drawing.SystemColors.WindowText
        DataGridViewCellStyle5.SelectionBackColor = System.Drawing.SystemColors.Highlight
        DataGridViewCellStyle5.SelectionForeColor = System.Drawing.SystemColors.HighlightText
        DataGridViewCellStyle5.WrapMode = System.Windows.Forms.DataGridViewTriState.[True]
        Me.gridViewSearch1.ColumnHeadersDefaultCellStyle = DataGridViewCellStyle5
        Me.gridViewSearch1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
        Me.gridViewSearch1.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Me.ma, Me.ten})
        Me.gridViewSearch1.DataSource = Me.TblsearchBindingSource
        Me.gridViewSearch1.Location = New System.Drawing.Point(315, 66)
        Me.gridViewSearch1.Name = "gridViewSearch1"
        Me.gridViewSearch1.RowHeadersVisible = False
        Me.gridViewSearch1.Size = New System.Drawing.Size(465, 367)
        Me.gridViewSearch1.TabIndex = 1050
        '
        'TblsearchBindingSource
        '
        Me.TblsearchBindingSource.DataMember = "tbl_search"
        Me.TblsearchBindingSource.DataSource = Me.DataSetSearch
        '
        'DataSetSearch
        '
        Me.DataSetSearch.DataSetName = "DataSetSearch"
        Me.DataSetSearch.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema
        '
        'ma
        '
        Me.ma.DataPropertyName = "ma"
        Me.ma.HeaderText = "ma"
        Me.ma.Name = "ma"
        Me.ma.ReadOnly = True
        Me.ma.Width = 80
        '
        'ten
        '
        Me.ten.DataPropertyName = "ten"
        Me.ten.HeaderText = "ten"
        Me.ten.Name = "ten"
        Me.ten.ReadOnly = True
        Me.ten.Width = 360
        '
        'frmNAP_DAUKY_TonCongNoNVBH
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.LightBlue
        Me.ClientSize = New System.Drawing.Size(792, 573)
        Me.Controls.Add(Me.gridViewSearch1)
        Me.Controls.Add(Me.CBoKH)
        Me.Controls.Add(Me.DataGridView1)
        Me.Controls.Add(Me.TxtKH)
        Me.Controls.Add(Me.Label9)
        Me.Controls.Add(Me.BtnClose)
        Me.Controls.Add(Me.txtTienCuoiKy)
        Me.Controls.Add(Me.btnDelete1)
        Me.Controls.Add(Me.btnNew)
        Me.Controls.Add(Me.btnSave)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Name = "frmNAP_DAUKY_TonCongNoNVBH"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "NAP DAU KY"
        CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.TbldottoncongnokhachhangBindingSource, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.DataSetNAP_DAUKY, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.gridViewSearch1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.TblsearchBindingSource, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.DataSetSearch, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region
    Private data1 As DataTable
    Private da As MySqlDataAdapter
    Dim myDT, tmp As New DataTable
    Dim strError As String = ""
    Dim myform As Form
    Dim sqlQuery As String = ""
    Dim flag_s As Boolean = False
    Sub SetclearData()
        txtTienCuoiKy.Text = "0"
        CBoKH.Text = ""
        TxtKH.Text = ""
    End Sub
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        ' Kiểm tra có nhập liệu chưa ?
        If Me.checkInput() Then
            Dim txtMaTK = Me.CBoKH.Text.Trim
            sqlQuery = "SELECT ma_khachhang FROM tbl_dot_toncongno_nhanvienbanhang WHERE  recycleID='" & globalVariale.NAPDAUKY & "' and ma_khachhang = '" & txtMaTK & "'"
            Dim existedMamon As Integer = moduleDatabaseConn.CheckRecordExisted(sqlQuery)
            If existedMamon = 1 Then ' Update record
                sqlQuery = "UPDATE tbl_dot_toncongno_nhanvienbanhang "
                sqlQuery += "SET "
                sqlQuery += "ma_khachhang = '" & txtMaTK & "'"
                sqlQuery += ", thanhtien_dauky = 0"
                sqlQuery += ", phatsinhno_trongky = 0"
                sqlQuery += ", thanhtoan_trongky = 0"
                sqlQuery += ", thanhtien_cuoiky = '" & Replace(CDec(Me.txtTienCuoiKy.Text.Trim), ",", ".") & "'"
                sqlQuery += " ,recycleID = '" & globalVariale.NAPDAUKY & "'"
                sqlQuery += " WHERE recycleID='" & globalVariale.NAPDAUKY & "' and ma_khachhang = '" & txtMaTK & "'"
                Dim updated As Integer = moduleDatabaseConn.ExecuteNonQuery(sqlQuery)
                If updated = 1 Then
                    MessageBox.Show("Cập nhật thông tin thành công !")
                    sqlQuery = "SELECT * FROM tbl_dot_toncongno_nhanvienbanhang where recycleID='" & globalVariale.NAPDAUKY & "'"
                    Me.loadCDTK(sqlQuery)
                Else
                    MessageBox.Show("Cập nhật thông tin không thành công: " & globalVariale.sqlMsgError)
                End If

            Else
                If existedMamon = 0 Then ' Insert record
                    sqlQuery = "INSERT INTO tbl_dot_toncongno_nhanvienbanhang "
                    sqlQuery += "(ma_khachhang,thanhtien_dauky,phatsinhno_trongky,thanhtoan_trongky,thanhtien_cuoiky,recycleID) "
                    sqlQuery += "VALUES "
                    sqlQuery += "("
                    sqlQuery += "'" & Me.CBoKH.Text.Trim & "', "
                    sqlQuery += "0, "
                    sqlQuery += "0, "
                    sqlQuery += "0, "
                    sqlQuery += "'" & Replace(CDec(Me.txtTienCuoiKy.Text.Trim), ",", ".") & "', "
                    sqlQuery += "'" & globalVariale.NAPDAUKY & "' "
                    sqlQuery += ")"
                    Dim inserted As Integer = moduleDatabaseConn.ExecuteNonQuery(sqlQuery)
                    If inserted = 1 Then
                        MessageBox.Show("Thêm thông tin thành công !")
                        sqlQuery = "SELECT * FROM tbl_dot_toncongno_nhanvienbanhang where recycleID='" & globalVariale.NAPDAUKY & "'"
                        Me.loadCDTK(sqlQuery)
                    Else
                        MessageBox.Show("Thêm thông tin không thành công: " & globalVariale.sqlMsgError)
                    End If
                Else ' SQLExeption: existedMaQuocGia = -1
                    MessageBox.Show("Lấy dữ liệu bị lỗi: " & globalVariale.sqlMsgError, "Lấy dữ liệu", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                End If
            End If
        End If


    End Sub
    Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
        SetclearData()
        CBoKH.Focus()
    End Sub
    Private Sub btnDelete1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete1.Click

        Try
            Dim iRow As Integer = Me.DataGridView1.CurrentRow.Index
            Me.CBoKH.Text = Me.DataGridView1.Item(1, iRow).Value
            moduleConstants.MessageWarning = "Bạn có muốn xóa " & Me.CBoKH.Text & " ? "
            If MessageBox.Show(moduleConstants.MessageWarning, globalVariale.msgTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = MsgBoxResult.Yes Then
                Dim sqlQuery As String = "DELETE FROM tbl_dot_toncongno_nhanvienbanhang WHERE recycleID='" & globalVariale.NAPDAUKY & "' and ma_khachhang = '" & Me.CBoKH.Text & "'"
                Dim deleting As Integer = moduleDatabaseConn.ExecuteNonQuery(sqlQuery)
                If deleting = 1 Then
                    MessageBox.Show("Xóa thông tin thành công !")
                    sqlQuery = "SELECT * FROM tbl_dot_toncongno_nhanvienbanhang where recycleID='" & globalVariale.NAPDAUKY & "'"
                    Me.loadCDTK(sqlQuery)
                    SetclearData()
                Else
                    MessageBox.Show("Xóa thông tin không thành công: " & globalVariale.sqlMsgError)
                End If
            End If
        Catch ex As Exception
            MessageBox.Show("Có lỗi khi Xóa thông tin  " & globalVariale.sqlMsgError)

        End Try


        'Dim txtMatk As String = Trim(Me.CBoKH.Text)
        'If Me.TxtKH.Text = "" Then
        '    MessageBox.Show("Bạn chưa chọn Mã để xóa !")
        'Else
        '    Dim txtTentk As String = Trim(Me.TxtKH.Text)
        '    moduleConstants.MessageWarning = "Bạn có muốn xóa " & txtMatk & "(" & txtTentk & ") ?"

        '    If MessageBox.Show(moduleConstants.MessageWarning, globalVariale.msgTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = MsgBoxResult.Yes Then
        '        Dim sqlQuery As String = "DELETE FROM tbl_dot_toncongno_nhanvienbanhang WHERE recycleID='" & globalVariale.NAPDAUKY & "' and ma_khachhang = '" & txtMatk & "'"
        '        Dim deleting As Integer = moduleDatabaseConn.ExecuteNonQuery(sqlQuery)
        '        If deleting = 1 Then
        '            MessageBox.Show("Xóa thông tin thành công !")
        '            sqlQuery = "SELECT * FROM tbl_dot_toncongno_nhanvienbanhang where recycleID='" & globalVariale.NAPDAUKY & "'"
        '            Me.loadCDTK(sqlQuery)
        '            SetclearData()
        '        Else
        '            MessageBox.Show("Xóa thông tin không thành công: " & globalVariale.sqlMsgError)
        '        End If
        '    End If
        'End If
    End Sub
    Private Sub frmNAP_DAUKY_TonCongNoNVBH_load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        moduleUtils.setDinhDangVietNam()
        Me.loadDanhSachKH()
        Me.loadCDTK("SELECT * FROM tbl_dot_toncongno_nhanvienbanhang where recycleID='" & globalVariale.NAPDAUKY & "'")
        SetclearData()
        Me.gridViewSearch1.Visible = False
        flag_s = True

    End Sub

    Private Sub BtnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClose.Click
        Me.Close()
    End Sub

    Private Function checkInput() As Boolean
        If Me.CBoKH.Text = "" Then
            MessageBox.Show("Bạn phải chọn mã!")
            Me.CBoKH.Focus()
            Return False
            Exit Function
        End If
        If IsNumeric(Me.txtTienCuoiKy.Text) = False Then
            MessageBox.Show("Bạn phải nhập số lượng là kiểu số !")
            Me.txtTienCuoiKy.Focus()
            Return False
            Exit Function
        End If

        Return True
    End Function
    Private Sub loadCDTK(ByVal sqlQuery As String)
        Me.DataGridView1.DataSource = moduleDatabaseConn.GetDataTable(sqlQuery)
    End Sub
    Private Sub loadDanhSachKH()
        Try
            Dim sqlQuery As String = ""
            sqlQuery = "SELECT  ma ,  ten  FROM tbl_nhanvienbanhang ORDER BY ma"
            data1 = moduleDatabaseConn.GetDataTable(sqlQuery)
            CBoKH.Items.Clear()
            CBoKH.LoadingType = MTGCComboBox.CaricamentoCombo.DataTable
            CBoKH.ColumnNum = 2
            CBoKH.ColumnWidth = "100;250"
            CBoKH.HighlightBorderColor = Color.Black
            CBoKH.GridLineHorizontal = True
            CBoKH.GridLineVertical = True
            CBoKH.ItemHeight = 17
            CBoKH.DropDownHeight = 300
            CBoKH.SourceDataTable = data1
            CBoKH.SelectedIndex = 1
        Catch ex As Exception

        End Try

    End Sub
    Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        Try
            Dim iRow As Integer = Me.DataGridView1.CurrentRow.Index
            Me.CBoKH.Text = Me.DataGridView1.Item(1, iRow).Value
            Me.txtTienCuoiKy.Text = Format(CDbl(Me.DataGridView1.Item(5, iRow).Value), "N0")
        Catch ex As Exception

        End Try


    End Sub

    Private Sub CBoKH_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles CBoKH.MouseClick
        Me.gridViewSearch1.Visible = False
        flag_s = True

    End Sub

    Private Sub CBoKH_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CBoKH.SelectedIndexChanged
        Me.gridViewSearch1.Visible = False
        flag_s = True
        Dim vtien As Double
        Try
            Me.TxtKH.Text = Me.CBoKH.SelectedItem.Col2
            sqlQuery = "select thanhtien_cuoiky from tbl_dot_toncongno_nhanvienbanhang where recycleID='" & globalVariale.NAPDAUKY & "' and ma_khachhang='" & Me.CBoKH.Text.Trim & "'"
            tmp = moduleDatabaseConn.GetDataTable(sqlQuery)
            If tmp.Rows.Count > 0 Then
                vtien = tmp.Rows.Item(0).Item(0)
            Else
                vtien = 0
            End If
            Me.txtTienCuoiKy.Text = Format(vtien, "N0")
        Catch ex As Exception
        End Try
    End Sub
    Private Sub gridViewSearch1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles gridViewSearch1.CellClick
        Dim row1 As Integer = Me.gridViewSearch1.CurrentRow.Index
        moduleUtils.setIndexComBo(Me.gridViewSearch1.Item(Me.ma.Index, row1).Value, Me.CBoKH, data1)
        Me.TxtKH.Text = CBoKH.SelectedItem.Col2
        Me.gridViewSearch1.Visible = False
        flag_s = True

    End Sub

    Private Sub TxtKH_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TxtKH.MouseClick
        Me.TxtKH.Text = " "
        Me.gridViewSearch1.Visible = True
        flag_s = False
    End Sub

    Private Sub TxtKH_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TxtKH.TextChanged
        If flag_s = True Then
            Me.gridViewSearch1.Visible = False
        Else
            Me.gridViewSearch1.Visible = True
            Dim view As DataView = New DataView(data1)
            view.RowFilter = " ma like '%" & Me.TxtKH.Text.Trim & "%' or ten like '%" & Me.TxtKH.Text.Trim & "%' "
            Me.gridViewSearch1.DataSource = view
        End If
    End Sub
End Class


